package com.usf.jprovider.schema.connector;

import java.text.ParseException;
import java.util.Date;

import com.usf.jprovider.constants.Constants;
import com.usf.jprovider.tools.DateTools;

public final class MysqlConnector extends AbstractConnector {

	public MysqlConnector() {
		super(Constants.MYSQL_DRIVER);
	}
	
	@Override
	public String IntegerFormater(String value) {
		return "'" + value + "'";
	}
	@Override
	public String DoubleFormater(String value) {
		return "'" + value + "'";
	}
	@Override
	public String DateFormater(String value, String format) throws ParseException {
		Date date = DateTools.valueOf(value, format);
		return "'" + new java.sql.Date(date.getTime()) + "'";
	}
	@Override
	public String StringFormater(String value) {
		return "'" + value + "'";
	}
	@Override
	public String FileSourceFormater(String value) {
		return "'" + value + "'";
	}

	@Override
	public String selectRandomize(String table, String column) {
		return "SELECT DISTINCT " + column + " FROM " + table +
				" ORDER BY RAND() LIMIT 1";
	}
	@Override
	public String selectRandomize(String table, String column, String queryValue) {
		return "SELECT DISTINCT " + column + " FROM " + table + " WHERE " + column + " " + queryValue +
				" ORDER BY RAND() LIMIT 1";
	}
	@Override
	public String selectRandomize(String query) {
		return query + " ORDER BY RAND() LIMIT 1";
	}
	
	@Override
	public String nextSequenceQuery(String name) {
		return ""; //TODO correct
	}

}
